<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
	<!-- UC强制全屏 -->
	<meta name="full-screen" content="yes">
	<!-- QQ强制全屏 -->
	<meta name="x5-fullscreen" content="true">
	<!-- UC应用模式 -->
	<meta name="browsermode" content="application">
	<!-- QQ应用模式 -->
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <#include "/common/css.ftl"/>
    <title>主机列表</title>
    <script language="javascript">
    	function showActionSheet(machineId,isAlive){
    	if(isAlive){
    		$.actions({
	    	  title: "选择操作",
	          actions: [
			  {
	          	className: "bg-warning",
			    text: "关机",
			    onClick: function() {
			      $.ajax({
					  url:'/machine/off/'+machineId,
					  type:'post',
					  data:{'${_csrf.parameterName}':'${_csrf.token}'},
					  dataType:'json',
					  success:function(result){
						if (result) {
					      $.toast("操作成功");
						}else{
					        $.toast("操作失败", "forbidden");
						}
						  
					  }
				  	});
			    }
			  },
			  {
			    className: "bg-danger",
			    text: "删除",
			    onClick: function() {
			    $.confirm({
				  title: '请确认',
				  text: '是否确认删除',
				  onOK: function () {
				      //点击确认
				      $.ajax({
						  url:'/machine/delete/'+machineId,
						  type:'post',
						  data:{'${_csrf.parameterName}':'${_csrf.token}'},
						  dataType:'json',
						  success:function(result){
							if (result) {
						      $.toast("操作成功");
						      window.location.reload();
							}else{
						        $.toast("操作失败", "forbidden");
							}
							  
						  }
					  	});
				  }
				});
			    
			    }
			  }]
			});
    	}else{
    		$.actions({
	    	  title: "选择操作",
	          actions: [{
	          	className: "bg-primary",
			    text: "唤醒",
			    onClick: function() {
			      $.ajax({
					  url:'/machine/wake/'+machineId,
					  type:'post',
					  data:{'${_csrf.parameterName}':'${_csrf.token}'},
					  dataType:'json',
					  success:function(result){
						if (result) {
					      $.toast("操作成功");
						}else{
					        $.toast("操作失败", "forbidden");
						}
						  
					  }
				  	});
			    }
			  },
			  {
			    className: "bg-danger",
			    text: "删除",
			    onClick: function() {
			    $.confirm({
				  title: '请确认',
				  text: '是否确认删除',
				  onOK: function () {
				      //点击确认
				      $.ajax({
						  url:'/machine/delete/'+machineId,
						  type:'post',
						  data:{'${_csrf.parameterName}':'${_csrf.token}'},
						  dataType:'json',
						  success:function(result){
							if (result) {
						      $.toast("操作成功");
						      window.location.reload();
							}else{
						        $.toast("操作失败", "forbidden");
							}
							  
						  }
					  	});
				  }
				});
			    
			    }
			  }]
			});
    	}
    		
    	}
    </script>
    </head>
    <#assign urlpath="machineList">
    <body>
	    <#include "/common/title.ftl"/>
	     <#if results?? && (results?size > 0) >
		    <div class="weui_grids">
			    <#list results as machine>
				  <a href="javascript:void(0);" class="weui_grid js_grid" data-id="button" onclick="showActionSheet('${machine.id}',${machine.isAlive?string('true', 'false')})">
				    <p class="weui_grid_label">
				      	${machine.name}</br>
				      	${machine.mac}</br>
				      	${(machine.hostName)!'暂未获取'}</br>
				      	${(machine.ip)!'暂未获取'}</br>
				      	${(machine.osType)!'暂未获取'}</br>
				      	${machine.isAlive?string('开机', '关机')}
				    </p>
				  </a>
				</#list>
			</div>
 		<#else>
 		<div class="weui_msg">
		  <div class="weui_text_area">
		    <h2 class="weui_msg_title">未添加主机</h2>
		  </div>
		</div>
 		</#if>
    <#include "/common/tabar.ftl"/>
    </body>
    <#include "/common/js.ftl"/>
</html>